<template>
	<view class="content bgw">
		<view v-if="identity==2">
			<view class="title">患者数据</view>
			<view class="dataWrap">
				<view class="data">
					<view class="all">
						<text class="blue">{{tongjiList.all}}</text>
						累计问诊
					</view>
					<view class="shu"></view>
					<view class="month">
						<text>{{tongjiList.month}}</text>
						本月
					</view>
					<view class="shu"></view>
					<view class="week">
						<text>{{tongjiList.week}}</text>
						本周
					</view>
				</view>
			</view>
			<view class="title">我的工作台</view>
			<view class="workWrap">
				<view class="work" v-for="(item, i) in workList" :key="i" @click="goNext(item.name)">
					<image :src="item.url" mode=""></image>
					{{item.name}}
				</view>
			</view>
		</view>

		<view class="workWrap" v-if="identity==1">
			<view class="work" v-for="(item, i) in workList2" :key="i" @click="goNext2(item.name)">
				<image :src="item.url" mode=""></image>
				{{item.name}}
			</view>
			<view class="work" @click="qiehuan" v-if="is_company==1">
				<image src="../../static/bg/tuiguang.png" mode=""></image>
				切换门诊
			</view>
		</view>
	</view>
</template>

<script>
	import commonUtil from "../../components/utils/format.js";
	import {
		indexList,
		tongji,
		jiebang,
		myInfo
	} from '../../request/api.js'
	export default {
		data() {
			return {
				identity: '',
				active: '',
				workList: [{
						name: '我的资料',
						url: '../../static/bg/ziliao.png'
					}, {
						name: '我的患者',
						url: '../../static/bg/ziliao.png'
					},
					{
						name: '我的订单',
						url: '../../static/bg/yijian.png'
					}, {
						name: '外治法订单',
						url: '../../static/bg/wzf.png'
					},
					{
						name: '处方管理',
						url: '../../static/bg/chufang.png'
					},
					{
						name: '我的收益',
						url: '../../static/bg/shouyi.png'
					},
					// {
					// 	name: '切换用户端',
					// 	url: '../../static/bg/ziliao.png'
					// }, 
					
					{
						name: '分享入驻',
						url: '../../static/bg/fenxiang.png'
					}, {
						name: '分享医馆',
						url: '../../static/bg/fenxiang.png'
					},{
						name: '解除绑定',
						url: '../../static/bg/jie.png'
					},  {
						name: '退出登录',
						url: '../../static/bg/jie.png'
					}
				],
				tongjiList: {
					"all": 0, //累积问诊
					"week": 0, //周
					"month": 0, //月
					"yuyuenum": 0, //预约统计
					"weeknum": 0, //周
					"monthnum": 0 //月
				},
				workList2: [{
						name: '我的就诊人',
						url: '../../static/bg/ziliao.png'
					}, {
						name: '我的订单',
						url: '../../static/bg/yijian.png'
					},
					// {
					// 	name: '我的地址',
					// 	url: '../../static/bg/tuiguang.png'
					// },
					{
						name: '我的代金券',
						url: '../../static/bg/zhenfei.png'
					},
					{
						name: '意见反馈',
						url: '../../static/bg/chufang.png'
					},
					{
						name: '外治法订单',
						url: '../../static/bg/wzf.png'
					}, {
						name: '退出登录',
						url: '../../static/bg/jie.png'
					}
					// , {
					// 	name: '切换医生端',
					// 	url: '../../static/bg/ziliao.png'
					// }
				],
				is_company: 0, //用户是否进入多门诊
				companyList:[],//用户下的门诊
				userid: '', //医生的id
			}
		},
		onShow() {
			this.identity = uni.getStorageSync('identity')
			// console.log(this.identity)
			if (this.identity == 2) {
				this.tongji();
			}else{
				this.indexList()
			}
		},
		onLoad() {
			this.identity = uni.getStorageSync('identity')
			if (this.identity == 2) {
				this.getMyInfo();
			}
		},
		methods: {
			// 医生信息
			getMyInfo() {
				myInfo().then(res => {
					if (res.code === 200) {
						this.userid = res.data.id;
					}
				})
			},
			// 医生端
			goNext(name) {
				let url
				if (name === '我的收益') {
					url = '../myEarnings/myEarnings'
				} else if (name === '处方管理') {
					url = '../prescription/prescription'
				} else if (name === '我的订单') {
					url = '../myOrder/myOrder'
				} else if (name === '我的资料') {
					url = '../myinfo/myinfo'
				} else if (name === '我的患者') {
					url = '../patientList/patientList'
				} else if (name === '切换用户端') {
					let member = uni.getStorageSync('member')
					if (!member) {
						uni.showModal({
							title: '提示',
							content: '您还不是用户，是否前往绑定！',
							success: function(res) {
								if (res.confirm) {
									uni.reLaunch({
										url: '/pages/login/login'
									})
								}
							}
						});
					} else {
						uni.setStorageSync('token', member.login_token)
						uni.setStorageSync('identity', 1)
						this.identity = 1
					}
					return
				} else if (name === '解除绑定') {
					// let that = this
					uni.showModal({
						title: '解除绑定',
						content: '解除绑定后，需重新授权后再次绑定！',
						success: function(res) {
							let token = uni.getStorageSync('token')
							let companyId = uni.getStorageSync('companyId')
							if (token) {
								jiebang().then(res => {
									uni.clearStorageSync()
									window.location.href = '?companyId=' + companyId + '&identity=2'
								})
							} else {
								window.location.href = '?companyId=' + companyId + '&identity=2'
							}
						}
					});
					return
				} else if (name === '外治法订单') {
					url = '../outside/outsideList'
				} else if (name === '分享入驻') {
					url = '../share/share?userid=' + this.userid
				} else if (name === '分享医馆') {
					url = '../share/share2'
				} else if (name === '退出登录') {
					uni.setStorageSync('token','')
					uni.setStorageSync('doctorToken','')
					uni.reLaunch({
						url: '/pages/login/login2'
					})
					return;
				} else {
					return
				}
				uni.navigateTo({
					url: url
				})
			},
			// 用户信息
			indexList() {
				indexList().then(res => {
					if (res.code === 200) {
						this.is_company = res.data.is_company;
						this.companyList = res.data.companys;
					}
				})
			},
			// 切换门诊
			qiehuan(){
				uni.navigateTo({
					url:'/pages/myCompanys/myCompanys?companyList='+JSON.stringify(this.companyList)
				})
			},
			// 医生统计信息
			tongji() {
				tongji().then(res => {
					if (res.code === 200) {
						res.data.all = commonUtil.million(res.data.all)
						res.data.month = commonUtil.million(res.data.month)
						res.data.week = commonUtil.million(res.data.week)
						this.tongjiList = res.data
					}
				})
			},
			// 用户端
			goNext2(name) {
				let url
				if (name === '我的订单') {
					url = '../myCode/myCode'
				} else if (name === '我的就诊人') {
					url = '../myVisit/myVisit'
				} else if (name === '我的地址') {
					url = '../myAddress/myAddress'
				}  else if (name === '我的代金券') {
					url = '../myCoupon/myCoupon'
				} else if (name === '意见反馈') {
					url = '../feedback/feedback'
				} else if (name === '切换医生端') {
					let doctor = uni.getStorageSync('doctor')
					if (!doctor) {
						uni.showModal({
							title: '提示',
							content: '您还不是医生，是否前往绑定！',
							success: function(res) {
								if (res.confirm) {
									uni.reLaunch({
										url: '/pages/login/login2'
									})
								}
							}
						});
					} else {
						uni.setStorageSync('token', doctor.login_token)
						uni.setStorageSync('identity', 2)
						this.identity = 2
						this.tongji()
					}
					return
				} else if (name === '外治法订单') {
					url = '../outside/outsideList2'
				} else if (name === '退出登录') {
					uni.reLaunch({
						url: '/pages/login/login'
					})
					return;
				} else {
					return
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 44upx 30upx;

		.title {
			font-size: 32upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			margin-bottom: 22upx;
		}

		.dataWrap {
			width: 100%;

			.data:last-of-type {
				margin-bottom: 68upx;
			}

			.data {
				height: 144upx;
				background: #FAFAFA;
				margin-bottom: 28upx;
				display: flex;
				align-items: center;

				>view {
					width: calc((100% - 4upx) / 3);
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					font-size: 28upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #414141;

					text {
						font-weight: bold;
					}

					.blue {
						color: #6996FE;
					}

					.yellow {
						color: #FCBE3F;
					}
				}

				.shu {
					width: 0upx;
					height: 58upx;
					border: 2upx solid #F0F0F0;
				}
			}
		}

		.workWrap {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.work {
				width: 336upx;
				height: 128upx;
				background: #FAFAFA;
				border-radius: 8upx;
				margin-bottom: 16upx;
				display: flex;
				align-items: center;
				font-size: 28upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #414141;

				image {
					width: 128upx;
					height: 128upx;
					// margin-right: 28upx;
					// margin-left: 34upx;
				}
			}
		}
	}
</style>
